package com.hnu.store.utils;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

public class CutVideo {
  public static void cut(String filePath,String path,String fileName,int start,int end) {
    File file = new File(filePath);
    try {
      RandomAccessFile raf1 = new RandomAccessFile(file,"r");
      //  1M
      byte[] bytes = new byte[1024];

      File targetFile = new File(path+File.separator+fileName);
      RandomAccessFile raf2 = new RandomAccessFile(targetFile,"rw");
      int length;
      int index=1;
      while ((length=raf1.read(bytes))!=-1) {
        if(index>=start&&index<=end) {
          raf2.write(bytes,0,length);
        } else if (index>end) {
          break;
        }
        index++;
      }
      raf2.close();
      raf1.close();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

}
